﻿using System.Collections.Generic;
using System.Xml.Linq;
using Engine;
using XmlUtilities;

namespace Game
{
    public static class GunTestManager
    {
        public static List<TestGunData> GunDatas = new List<TestGunData>();

        public static void Initialize()
        {
            XElement xElement = ContentManager.Get<XElement>("GunsTest");
            IEnumerator<XElement> enumerator = xElement.Elements().GetEnumerator();
            while (enumerator.MoveNext())
            {
                XElement current = enumerator.Current;
                TestGunData testGunData = new TestGunData
                {
                    Index = XmlUtils.GetAttributeValue<int>(current, "Index"),
                    BulletValue = XmlUtils.GetAttributeValue<int>(current, "BulletValue"),
                    AmmunitionValue = XmlUtils.GetAttributeValue<int>(current, "AmmunitionValue"),
                    MaxBulletCount = XmlUtils.GetAttributeValue<int>(current, "MaxBulletCount"),
                    FireInterval = XmlUtils.GetAttributeValue<float>(current, "FireInterval"),
                    Recoil = XmlUtils.GetAttributeValue<Vector2>(current, "Recoil"),
                    Cluster = XmlUtils.GetAttributeValue<int>(current, "Cluster"),
                    Deviation = XmlUtils.GetAttributeValue<float>(current, "Deviation"),
                    FireParticleOffset = XmlUtils.GetAttributeValue<Vector3>(current, "FireParticleOffset"),
                    FireAudio = XmlUtils.GetAttributeValue<string>(current, "FireAudio"),
                    IsScopeEnable = XmlUtils.GetAttributeValue<bool>(current, "IsScopeEnable"),
                    BoltOffset = XmlUtils.GetAttributeValue<float>(current, "BoltOffset")
                };
                if (testGunData.Index > 0)
                {
                    GunDatas.Add(testGunData);
                }
            }
        }

        public static TestGunData GetGunData(int id)
        {
            return GunDatas.Find((TestGunData gunData) => gunData.Index == id);
        }
    }
}